package cn.sciento.dd.service.impl;

import javax.annotation.Resource;
import org.apache.commons.codec.digest.DigestUtils;
import cn.sciento.dd.dto.GetTicketResultDTO;
import cn.sciento.dd.service.DingTicketService;
import org.springframework.web.client.RestTemplate;

public class DingTicketServiceImp implements DingTicketService {
  @Resource(name = "wdRestTemplate")
  protected RestTemplate restTemplate;
  
  public GetTicketResultDTO getTicket(String accessToken, String type) {
    return (GetTicketResultDTO)this.restTemplate.getForObject("https://oapi.dingtalk.com/get_jsapi_ticket?access_token=" + accessToken + "&type=" + type, GetTicketResultDTO.class);
  }
  
  public String signature(String ticket, String nonceStr, long timeStamp, String url) {
    String plain = "jsapi_ticket=" + ticket + "&noncestr=" + nonceStr + "&timestamp=" + timeStamp + "&url=" + url;
    return DigestUtils.sha1Hex(plain);
  }
}
